<template>
	<view class="container">
		<view class="strength-test">
			<uni-forms ref="form" :model="form" labelWidth="150px" label-align="right">
				<uni-forms-item label="学号" name="studentCode">
					<uni-easyinput v-model="form.studentCode" placeholder="请输入学号" disabled />
				</uni-forms-item>
				<uni-forms-item label="学员姓名" name="studentName" required>
					<uni-easyinput v-model="form.studentName" placeholder="请输入学员姓名" disabled />
				</uni-forms-item>
				<uni-forms-item label="身高(cm)" name="height" required>
					<uni-easyinput v-model="form.height" placeholder="请输入身高(cm)" />
				</uni-forms-item>
				<uni-forms-item label="体重(kg)" name="weight" required>
					<uni-easyinput v-model="form.weight" placeholder="请输入体重(kg)" />
				</uni-forms-item>
				<uni-forms-item label="摸高(cm)" name="touchHigh" required>
					<uni-easyinput v-model="form.touchHigh" placeholder="请输入摸高(cm)" />
				</uni-forms-item>
				<uni-forms-item label="立定(cm)" name="standingLeap" required>
					<uni-easyinput v-model="form.standingLeap" placeholder="请输入立定(cm)" />
				</uni-forms-item>
				<uni-forms-item label="一分钟跳绳-单摇(n)" name="ropeSkipping" required>
					<uni-easyinput v-model="form.ropeSkipping" placeholder="请输入一分钟跳绳-单摇(n)" />
				</uni-forms-item>
				<uni-forms-item label="一分钟跳绳-双摇(n)" name="ropeSkippingDouble" required>
					<uni-easyinput v-model="form.ropeSkippingDouble" placeholder="请输入一分钟跳绳-双摇(n)" />
				</uni-forms-item>
				<uni-forms-item label="备注" name="remark">
					<uni-easyinput v-model="form.remark" placeholder="请输入备注" />
				</uni-forms-item>
			</uni-forms>
			<button type="primary" @click="submit"
				style="color:#ffffff;backgroundColor:#993399;borderColor:#993399;">提交</button>
		</view>
	</view>
</template>

<script>
	import { updateStrengthtest } from "@/api/puyu/strengthtest";
	import { listStudents } from "@/api/puyu/student";

	export default {
		data() {
			return {
				// 学员数据
				studentList: [],
				form: {
					studentCode: "",
					studentName: "",
					remark: ""
				},
				rules: {
					studentName: {
						rules: [{
							required: true,
							errorMessage: '学员姓名不能为空'
						}]
					},
					height: {
						rules: [{
							required: true,
							errorMessage: '身高不能为空'
						}, {
							format: 'number',
							errorMessage: '身高只能输入数字'
						}]
					},
					weight: {
						rules: [{
							required: true,
							errorMessage: '体重不能为空'
						}, {
							format: 'number',
							errorMessage: '体重只能输入数字'
						}]
					},
					touchHigh: {
						rules: [{
							required: true,
							errorMessage: '摸高不能为空'
						}, {
							format: 'number',
							errorMessage: '摸高只能输入数字'
						}]
					},
					standingLeap: {
						rules: [{
							required: true,
							errorMessage: '立定不能为空'
						}, {
							format: 'number',
							errorMessage: '立定不能为空只能输入数字'
						}]
					},
					ropeSkipping: {
						rules: [{
							required: true,
							errorMessage: '一分钟跳绳-单摇不能为空'
						}, {
							format: 'number',
							errorMessage: '一分钟跳绳-单摇只能输入数字'
						}]
					},
					ropeSkippingDouble: {
						rules: [{
							required: true,
							errorMessage: '一分钟跳绳-双摇不能为空'
						}, {
							format: 'number',
							errorMessage: '一分钟跳绳-双摇只能输入数字'
						}]
					},
				},
			}
		},
		computed: {
		},

		created() {
			// 获取学员下拉列表
			this.getStudentLsit();
		},
		onLoad(option) {
		  const item = JSON.parse(decodeURIComponent(option.item));
		  this.form = item;
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		methods: {
			/** 查询学员列表 */
			getStudentLsit() {
				listStudents().then(response => {
					this.studentList = response.data;
				});
			},
			submit(ref) {
				this.loading = true;
				this.$refs.form.validate().then(res => {
					updateStrengthtest(this.form).then(response => {
						this.$modal.msgSuccess("修改成功!")
						this.loading = false;
						this.$tab.navigateBack();
					})
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
	}

	.strength-test {
		padding: 15px;
		background-color: #fff;
	}
</style>